package com.itheima.exception;

import com.itheima.po.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    //全局异常处理
    @ExceptionHandler(Exception.class)
    public R error(Exception e) {
        log.error("进行了全局处理" );
        e.printStackTrace();
        return R.error().message("执行了全局异常处理");
    }

    //特定异常处理
    @ExceptionHandler(ArithmeticException.class)
    public R error2(ArithmeticException e) {
        log.error(e.getMessage());
        e.printStackTrace();
        return R.error().message("ArithmeticException算数异常");
    }

}
